# -*- coding: utf-8 -*-
import unittest
from structures.unionfind import UnionFind


class UnionFindTest(unittest.TestCase):

    def test_create_unionfind(self):
        unionfind = UnionFind(['V1', 'V2'])

        self.assertEqual(2, unionfind.count())

    def test_create_unionfind_union_check_count(self):
        unionfind = UnionFind(['V1', 'V2'])

        self.assertEqual(2, unionfind.count())

        unionfind.union('V1', 'V2')

        self.assertEqual(1, unionfind.count())

    def test_build_example_from_book_check_count(self):
        items = 'ijstuvwxyz'

        unionfind = UnionFind(items)

        self.assertEqual(len(items), unionfind.count())

        unionfind.union(unionfind.find('w'), unionfind.find('u'))
        unionfind.union(unionfind.find('s'), unionfind.find('u'))
        unionfind.union(unionfind.find('t'), unionfind.find('v'))
        unionfind.union(unionfind.find('z'), unionfind.find('v'))
        unionfind.union(unionfind.find('i'), unionfind.find('x'))
        unionfind.union(unionfind.find('y'), unionfind.find('j'))
        unionfind.union(unionfind.find('x'), unionfind.find('j'))

        self.assertEqual(3, unionfind.count())

        unionfind.union(unionfind.find('u'), unionfind.find('v'))

        self.assertEqual(2, unionfind.count())
